﻿Namespace Controle
    Public Class YCImageButton
        Inherits ImageButton

#Region "Variaveis"

        Private pTipo As EnumTipo

        Private pLinkAtivado As String = Nothing
        Private pLinkDesativado As String = Nothing

        Private pToolTipAtivado As String = Nothing
        Private pToolTipDesativado As String = Nothing

#End Region

        Public Enum EnumTipo
            None = 0
            AtivadoDesativado = 1
        End Enum

#Region "Propriedades"

        Public Property Tipo() As EnumTipo
            Get
                Return pTipo
            End Get
            Set(ByVal value As EnumTipo)
                pTipo = value
            End Set
        End Property

        Public Property LinkImagemAtivado() As String
            Get
                Return pLinkAtivado
            End Get
            Set(ByVal value As String)
                pLinkAtivado = value
            End Set
        End Property

        Public Property LinkImagemDesativado() As String
            Get
                Return pLinkDesativado
            End Get
            Set(ByVal value As String)
                pLinkDesativado = value
            End Set
        End Property

        Public Property Status() As Boolean
            Get
                Return IIf(String.IsNullOrEmpty(Me.Attributes("Status")), True, Me.Attributes("Status"))
            End Get
            Set(ByVal value As Boolean)
                Me.Attributes.Add("Status", value)
            End Set
        End Property

        Private Property ToolTipAtivado() As String
            Get
                Return pToolTipAtivado
            End Get
            Set(ByVal value As String)
                pToolTipAtivado = value
            End Set
        End Property

        Private Property ToolTipDesativado() As String
            Get
                Return pToolTipDesativado
            End Get
            Set(ByVal value As String)
                pToolTipDesativado = value
            End Set
        End Property

#End Region

        Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
            MyBase.OnPreRender(e)
            Select Case Tipo
                Case EnumTipo.None

                Case EnumTipo.AtivadoDesativado
                    Me.ToolTip = IIf(Status, pToolTipAtivado, pToolTipDesativado)
                    Me.Attributes.Add("Status", Status)
                    Me.ImageUrl = ResolveUrl(IIf(Status, pLinkAtivado, pLinkDesativado))
            End Select
        End Sub

        Protected Overrides Sub OnClick(ByVal e As System.Web.UI.ImageClickEventArgs)
            MyBase.OnClick(e)

            Select Case Tipo
                Case EnumTipo.None

                Case EnumTipo.AtivadoDesativado
                    Status = Not Status
            End Select

        End Sub




    End Class
End Namespace